package vn.edu.thptduongbachmai.model;

import com.vng.zing.common.HReqParam;
import com.vng.zing.logger.ZLogger;
import com.vng.zing.stats.Profiler;
import com.vng.zing.stats.ThreadProfiler;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.json.simple.JSONObject;
import vn.edu.thptduongbachmai.common.TemplateManager;
import vn.edu.thptduongbachmai.model.data.UsersModel;
import vn.edu.thptduongbachmai.model.pojo.Users;

/**
 *
 * @author tiennv4
 */
public class SignUpModel{
//
//	private static final Logger _Logger = ZLogger.getLogger(SignUpModel.class);
//	public static final SignUpModel Instance = new SignUpModel();
//	public static String FAIL = "Someone already has that username. Try another?";
//	public static String SUCCESS = "Successful";
//
//	private SignUpModel() {
//	}
//
//	@Override
//	public void process(HttpServletRequest req, HttpServletResponse resp) {
//		ThreadProfiler profiler = Profiler.getThreadProfiler();
//		try {
//			String username = HReqParam.getString(req, "u", "");
//			String password = HReqParam.getString(req, "p", "");
//			String displayname = HReqParam.getString(req, "d", "");
//			boolean success = false;
//			if (!username.isEmpty() && !password.isEmpty()) {
//			int userId = UsersModel.Instance.exist(username);
//				if (userId < 0) {
//					Users user = new Users(username, password, displayname);
//					success = UsersModel.Instance.put(user, 0);
//				} else {
//				}
//			}
//			renderPageJSON(req, resp, success);
//
//		} catch (Exception ex) {
//			_Logger.error(ex.getMessage(), ex);
//		}
//	}
//
//	public void renderPageJSON(HttpServletRequest req, HttpServletResponse resp, boolean success) {
//		JSONObject ret = new JSONObject();
//		if (success) {
//			ret.put("error", 0);
//			ret.put("message", SUCCESS);
//		} else {
//			ret.put("error", -1);
//			ret.put("message", FAIL);
//		}
//		TemplateManager.printJSON(ret.toJSONString(), resp);
//	}
}
